Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark comptime int hardcoded address pointee as a run time variable #1171 #1868

Merged
merged 2 commits into from
Jan 4, 2019

Conversation

justinbalexander
Copy link
Contributor

This fixes the compiler error from #1171.

Without this line, it was set to ConstPtrMutComptimeVar.

@andrewrk
Copy link
Member

andrewrk commented Jan 4, 2019

Looks good. Can you add a new test to cover this? Something like:

const myP = @intToPtr(*u16, 0x2300);

test "mutate through ptr initialized with constant intToPtr value" {
  myP.* = myP.* | 10;
}

Probably a good place for it would be test/cases/inttoptr.zig.

@justinbalexander
Copy link
Contributor Author

justinbalexander commented Jan 4, 2019 via email

@andrewrk
Copy link
Member

andrewrk commented Jan 4, 2019

Oops, good point. What we can do is put the logic in an if statement that will always be false, but make the compiler unable to determine the value at compile-time, so that it must analyze the branch. One way to do this, for example, is to pass false as a bool parameter, and then do an if on that bool.

This may be another good candidate for LLVM IR tests, when I get around to introducing that kind of test.

@justinbalexander
Copy link
Contributor Author

Like so?

test "mutate through ptr initialized with constant intToPtr value" {
    forceCompilerAnalyzeBranchHardCodedPtrDereference(false);
}

fn forceCompilerAnalyzeBranchHardCodedPtrDereference(x: bool) void {
    const hardCodedP = @intToPtr(*volatile u8, 0xdeadbeef);
    if (x) {
        hardCodedP.* = hardCodedP.* | 10;
    } else {
        return;
    }
}

It does pass.

@andrewrk
Copy link
Member

andrewrk commented Jan 4, 2019

Looks good to me.

@justinbalexander
Copy link
Contributor Author

justinbalexander commented Jan 4, 2019 via email

@andrewrk
Copy link
Member

andrewrk commented Jan 4, 2019

It used to do that implicitly, but not anymore. There are some problems to solve when trying to reinstate that behavior. The issue to track is #425. If we ever changed this behavior, a lot of tests would have to be modified, which rely on this behavior. So safe to assume that this new test case would be part of that audit.

@justinbalexander
Copy link
Contributor Author

Do I need to re-trigger the build before acceptance?

@andrewrk
Copy link
Member

andrewrk commented Jan 4, 2019

It's building. Should be done in about an hour. But enough of the tests pass that I'm confident it will finish successfully, so I'll go ahead and merge. Thanks again for the fix!

@andrewrk andrewrk merged commit 1f08be4 into ziglang:master Jan 4, 2019
@justinbalexander justinbalexander deleted the hardcoded_address_deref branch January 4, 2019 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants